package com.liu.demo1.testDemo;

import org.junit.Test;

/**
 * @author liusiyu
 * @ClassName Proxy
 * @date 2022年01月13日 17:10
 */
public class Proxy {
    //静态代理方法
    @Test
    public void Test1(){
        SmsServiceImpl smsService = new SmsServiceImpl();
        //SmsService smsProxy = new SmsProxy(smsService);
        SmsProxy smsProxy = new SmsProxy(smsService);
        smsProxy.send("java");
    }
}

interface SmsService{
    public String send(String mseeage);
}

class SmsServiceImpl implements SmsService{

    @Override
    public String send(String message) {
        System.out.println("message = " + message);
        return message;
    }
}

class SmsProxy implements SmsService{

    private SmsService smsService;

    public SmsProxy(SmsService smsService){
        this.smsService =smsService;
    }

    @Override
    public String send(String message) {
        System.out.println("我代理了这个发送接口，准备发送了");
        smsService.send(message);
        System.out.println("我发送完啦");
        return null;
    }

}
